{template 'common/header'}
<link href="{MODULE_URL}template/web/css/classlist.css" rel="stylesheet" type="text/css">
    <div class="list_th">
        <div class="td" style=" width:40%;">
            <div class="left_padding">分类名称</div>
        </div>
        <div class="td text-center" style=" width:30%;">排序</div>
        <div class="td text-center" style=" width:30%;">
            <div class="list_right text-center">操作</div>
        </div>
        <div class="clear"></div>
    </div>
    {if $class}
    {loop $class $k $o}
    <div class="list_tr link_bk">
            <div class="td text-center" style=" width:40%;">
                <div class="category_img J_show" id="{$o['id']}" level="1"></div>
                <div class="category_input">
                    <input name="save_id[]" type="hidden" value="{$o['id']}"/>
                    <input name="categoryname[]" type="text" class="input_text_default small" maxlength="20"
                           value="{$o['categoryname']}" id="class_{$o['id']}" style=" width: 120px;"/>
                    <span style="color:#999999; margin-left: 5px; font-size: 13px;">[id:{$o['id']}]</span>
                </div>
                <div class="clear"></div>
            </div>
            <div class="td text-center" style=" width:30%;" >
              <input name="categoryname[]" type="text" class="input_text_default small text-center" maxlength="20"
                           value="{$o['category_order']}" id="order_{$o['id']}"  style=" width: 120px;"/>
                
            </div>
            <div class="td edit text-center" style=" width:30%;">
                <div class="list_right btn">
                    <a href="{php echo $this->createWebUrl('classedit',array('oid'=>$o['id']));}">修改</a>
                    <a class="gray delete" did="{$o['id']}">删除</a>
                    <a class="green hide_{$o['ishide']} ishide" did="{$o['id']}" sid="{$o['ishide']}">显隐</a>
                    <a class="save_class" did="{$o['id']}">保存修改</a>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    {/loop}
    {else}
    {/if}
    <div class="list_tr">
        <div class="td" style="width: 60%;">
            <a class="J_add category_list_add" level="1" pid="0" href="{php echo $this->createWebUrl('classadd');}">添加分类</a>
            <div class="clear"></div>
        </div>
    </div>
<div class="list_tr">    
<div class="text-center">
  {php echo $pager;}
</div> 
</div>
<style type="text/css">.right-content{padding: 0;}</style>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script src="{MODULE_URL}public/js/Toast.js"></script>  
<script type="text/javascript">
$(document).ready(function(){
    var Maxlevel="1";//最多分类层数
    //打开子菜单
    $(document).on('click','.J_show',function () {
        var sub_box = $(this).closest(".list_tr").next('.j_smalldiv');
        var level = $(this).attr('level');
        sub_box.is(':visible') ? $(this).removeClass("show") : $(this).addClass("show");
        if (sub_box.length == 0 && level < Maxlevel) {
            get_menu($(this).attr('id'), $(this).closest(".list_tr"), level);
        }
        else {
            sub_box.toggle();
        }

    });
    // //生成分类
    // function get_menu(pid, thisobj, level) {
    //     var tsTimeStamp = new Date().getTime();
    //     $.getJSON("{php echo $this->createWebUrl('district/web_getcategory_district');}", {"pid": pid}, function (result) {
    //         if (result.status == 1) {
    //             var html = "";
    //             var leftbg = "";
    //             var i = 1;
    //             level++;
    //             for (x in result.data) {
    //                 html += "<div class=\"list_tr link_bk\">";
    //                 html += "<div class=\"td\" style=\"width:60%\">";
    //                 html += "<div class=\"category_sub_img l" + level + "\">&nbsp;</div>";
    //                 html += "<div class=\"category_img J_show\" id=\"" + result.data[x]['id'] + "\" level=\"" + level +"\"></div>";
    //                 html += "<div class=\"category_input\">";
    //                 html += "<input name=\"save_id[]\" type=\"hidden\" value=\"" + result.data[x]['id'] + "\"/>";
    //                 html += "<input name=\"pid[]\" type=\"hidden\" value=\"" + result.data[x]['category_order'] + "\"/>";
    //                 html += "<input name=\"categoryname[]\" type=\"text\" value=\"" + result.data[x]['categoryname'] + "\" class=\"input_text_default small\" maxlength=\"20\" style=\"width: 120px;\"/>";
    //                 html += "<span style=\"color:#999999; margin-left: 5px; font-size: 13px;\">(id:" + result.data[x]['id'] + ")</span>";
    //                 html += "</div>";
    //                 html += "<div class=\"clear\"></div>";
    //                 html += "</div>";
    //                 html += "<div class=\"td\" style=\"width:10%\">"+result.data[x]['category_order']+"</div>";
    //                 html += "<div class=\"td edit\" style=\"width:30%\"><div class=\"list_right btn\">";
    //                 if (level < Maxlevel) {
    //                     html += "<a href=\"{php echo $this->createWebUrl('web_city_add');}&cid=" + result.data[x]['id'] + "\">添加子类</a>";
    //                 }
    //                 html += "<a href=\"{php echo $this->createWebUrl('web_city_edit');}&cid=" + result.data[x]['id'] + "\">修改</a>";
    //                 html += "<a did=\""+result.data[x]['id']+"\" class=\"gray delete\">删除</a>";
    //                 html += "<a class=\"green hide_"+result.data[x]['ishide']+" ishide\" did=\""+result.data[x]['id']+"\" sid=\""+result.data[x]['ishide']+"\">显隐</a>";
    //                 html += "</div></div>";
    //                 html += "<div class=\"clear\"></div>";
    //                 html += "</div>";
    //                 i++;
    //             }
    //             if (level <= Maxlevel) {
    //                 html += "<div class=\"list_tr\"><div class=\"td\" style=\"width:60%;\"><div class=\"category_sub_img last l" + level + "\">&nbsp;</div><a class=\"J_add category_list_add\" level=\"" + level + "\" pid=\"" + pid + "\" href=\"{php echo $this->createWebUrl('web_city_add');}&cid="+pid+"\">添加分类</a><div class=\"clear\"></div></div></div>";
    //             }
    //             thisobj.after('<div class="j_smalldiv">' + html + '</div>');
    //         }
    //     });
    // }
    // //添加分类
    // // $(document).on('click','.j_add', function () {
    // //     var pid=$(this).attr('pid');
    // //     window.location.href = "{php echo $this->createWebUrl('web_city_add');}&cid="+pid;
    // // }); 
    $(document).on('click','.delete', function () {
              if(!confirm("确定要删除该分类吗！")){                
                   window.event.returnValue=false;
               }else{
                   $.ajax({
                       url:"{php echo $this->createWebUrl('classdel');}&version_id="+"{$_GPC['version_id']}",
                       data:{did:$(this).attr('did')},
                       dataType:"json",
                       type:"post",
                      success:function(res){
                         if(res.status== 1){
                             mqToast({type:1,context: res.msg}); 
                             window.location.reload();  
                             return false;
                         }else{
                             mqToast({type:1,context: res.msg}); 
                             return false;
                         }
                      }
                    })                    
               }        
    });   
    $(document).on('click','.ishide',function(){
            var ssid = $(this).attr('sid');
            var obj  = $(this);
           $.ajax({
                     url:"{php echo $this->createWebUrl('classishide');}&version_id="+"{$_GPC['version_id']}",
                     data:{did:$(this).attr('did'),sid:$(this).attr('sid')},
                     dataType:"json",
                     type:"post",
                    success:function(res){
                       if(res.status== 1){  
                           if(ssid=='1'){   
                            obj.addClass('hide_0');
                            obj.attr('sid','0'); 
                           }else{                           
                            obj.removeClass('hide_0');
                            obj.attr('sid','1');
                           }
                            mqToast({type:1,context: res.msg}); 
                            return false;
                       }else{
                           mqToast({type:1,context: res.msg}); 
                           return false;
                       }
                    }
                  });
    });
     $(document).on('click','.save_class',function(){
        var _this = $(this);
        var did = _this.attr('did');
        var classname  =$.trim($('#class_'+did).val());
        var classorder = $.trim($('#order_'+did).val());
        $.ajax({
           url:"{php echo $this->createWebUrl('save_classedit_summary');}&version_id="+"{$_GPC['version_id']}",
           data:{did:did,classname:classname,classorder:classorder},
           dataType:"json",
           type:"post",
          success:function(res){
            if(res.status=='1'){
                mqToast({type:1,context: res.msg})
                return false;
            }else{
                mqToast({type:1,context: res.msg})
                return false;
            }
          }
        });
     });     
});
</script>
{template 'common/footer'}